package com.jalarbee.stock.product.util;

import com.jalarbee.stock.product.business.Quantity;
import com.jalarbee.stock.product.business.Unit;

/**
 *
 * @author devel
 */
public class QuantityUtil {

    public static Quantity parse(String string) throws Exception {
        StringBuilder count = new StringBuilder();
        StringBuilder unit = new StringBuilder();
        try {
            for(char c : string.toCharArray()) {
                if(Character.isLetter(c)) {
                    unit.append(c);
                } else {
                    count.append(c);
                }
            }
            return new Quantity(Integer.parseInt(count.toString().trim()), Unit.valueOf(unit.toString().trim()));
        } catch(Exception exception) {
            throw exception;
        }

    }

}
